<?php
require_once "../class/fenajax.class.php";
include "../dyn/connexion.php";

$f = new fenAjax("Formulaire validation",0);

if(isset($_POST['mode']) and isset($_POST['id_validation']) and isset($_POST['statut'])) {
	
	$mode = $_POST['mode'];
	$id_validation = $_POST['id_validation'];
	$statut = $_POST['statut'];
	
	if( !in_array($mode,array(1,2,3,11,12,13)))
		$f->ajaxErreur("Fonction non supportée","Ce mode n'est pas supporté pour ce module");
		
	if($mode == 1){			$header = "Selectionner le statut"; 		$nomAction = "Valider";		$disable = ""; }
	else if($mode == 2){	$header = "Selectionner la visibilité"; 	$nomAction = "Valider"; 	$disable = ""; }
	else if($mode == 3){	$header = "Confirmer la validation"; 		$nomAction = "Confirmer"; 	$disable = ""; }
	else{					$header = "Confirmer le refus"; 			$nomAction = "Refuser"; 	$disable = ""; }
	
	$f->retourAjax["boutton"] = $nomAction;
	$f->retourAjax["header"] = $header;
	
	$form = "<div id=\"feedback\"></div><br />";
	
	$form .= "<form action=\"#\" method=\"post\" onSubmit=\"return actionValidation($(this));\">";
	
	if ($mode == 1 or $mode == 2) {
		if ($mode == 1) {
			$res = mysql_query("SELECT * FROM Utilisateur WHERE  id = '".$id_validation."' ;");
		}
		if ($mode == 2) {
			$res = mysql_query("SELECT * FROM Texte WHERE  id = '".$id_validation."' ;");
		}
		
		while($row = mysql_fetch_array($res)) {
		
			$form .= "<br /><label class=\"formInfos\" for=\"statut\">Statut :</label>
					<select id=\"statut\" name=\"statut\" $disable>";
					
					if ($mode == 1) {
						$form .= "<option value=\"1\" selected=\"selected\">Contributeur</option>
							<option value=\"2\">Adhérent</option>
							<option value=\"3\">Animateur</option>
							<option value=\"4\">Administrateur</option>
						";
					}
					
					if ($mode == 2) {
						$form .= "<option value=\"1\" selected=\"selected\">Privé</option>
							<option value=\"2\">Restreint</option>
							<option value=\"3\">Public</option>
						";

					}
					
			$form .= "</select>";
			
			$form .= "<input type=\"hidden\" name=\"id_validation\" value=\"".$id_validation."\" />";
		}
	}
	
	if ($mode == 3) {
		$form .= BMInfo("Note: Confirmer ou annuler la validation du commentaire",false);
		
		$form .= "<input type=\"hidden\" name=\"id_validation\" value=\"".$id_validation."\" />
				<input type=\"hidden\" name=\"statut\" value=\"1\" />
		";
	}
	
	if( in_array($mode,array(11,12,13))){
		if ($mode == 11) {
			$name = "de l'utilisateur";
		}
		if ($mode == 12) {
			$name = "du texte";
		}		
		if ($mode == 13) {
			$name = "du commentaire";
		}
			
		$form .= BMInfo("Note: Confirmer ou annuler le refus de validation ".$name."",false);
		
		$form .= "<input type=\"hidden\" name=\"id_validation\" value=\"".$id_validation."\" />
				<input type=\"hidden\" name=\"statut\" value=\"-1\" />
		";
	}
	
	
	$form .= "<input type=\"hidden\" name=\"mode\" value=\"".$mode."\" />
	</form>";
	
	$f->retourAjax["erreur"] = false;
	$f->retourAjax["msg"] = $form;
}

$f->endAjax();
?>